package com.maple.soa.lock;

/**
 * 缓存行对齐，提高效率
 * @author lijian
 * @date 2021/4/23 0:33
 */
public class L03_CacheLinePadding {
    private static class P {
        public volatile long p1,p2,p3,p4,p5,p6,p7;
    }
    private static class T extends P {
        public volatile long x = 0L;
    }

    public static T[] arr = new T[2];
    static {
        arr[0] = new T();
        arr[1] = new T();
    }

    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread(() -> {
            for (long i = 0; i < 1000_0000L; i++) {
                arr[0].x = i;
            }
        });

        Thread t2 = new Thread(() -> {
            for (long i = 0; i < 1000_0000L; i++) {
                arr[1].x = i;
            }
        });

        final long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(System.currentTimeMillis() - start);
    }


}
